package com.ysd.lis.service.sta.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.dto.sta.StaBreakPointDto;
import com.ysd.lis.dto.sta.StaBreakPointMapperCategoryDto;
import com.ysd.lis.dto.sta.StaBreakPointMapperCategoryParam;
import com.ysd.lis.entity.sta.StaAntibioticsDict;
import com.ysd.lis.entity.sta.StaBreakPoint;
import com.ysd.lis.entity.sta.StaGermDict;
import com.ysd.lis.mapper.sta.StaBreakPointMapper;
import com.ysd.lis.mapper.sta.StaGermDictMapper;
import com.ysd.lis.request.Params;
import com.ysd.lis.service.SysBasDictDetailService;
import com.ysd.lis.service.sta.StaBreakPointService;
import com.ysd.util.ToolsUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wanghuaixing
 * @since 2025-01-16
 */
@Service
public class StaBreakPointServiceImpl extends ServiceImpl<StaBreakPointMapper, StaBreakPoint> implements StaBreakPointService {

    @Autowired
    StaBreakPointMapper staBreakPointMapper;
    @Autowired
    StaGermDictMapper staGermDictMapper;
    @Autowired
    SysBasDictDetailService sysBasDictDetailService;

    @Override
    public Result findBreakPointList(Params params) {
        Page<StaBreakPoint> page = new Page<>();
        page.setCurrent(params.getPageIndex());
        page.setSize(params.getPageSize());

        LambdaQueryWrapper<StaBreakPoint> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StaBreakPoint::getDelFlag, 0);
        if (!StringUtils.isEmpty(params.getSearchValue())) {
            queryWrapper.and(wrapper -> wrapper.like(StaBreakPoint::getOrganismCode, params.getSearchValue()));
        }
        Page<StaBreakPoint> bacBreakPointPage = staBreakPointMapper.selectPage(page, queryWrapper);
        return Result.succ(1, "查询成功", bacBreakPointPage);
    }

    @Override
    public Result addBreakPoint(StaBreakPoint staBreakPoint) {
        int i = staBreakPointMapper.insert(staBreakPoint);
        if (i > 0) {
            return Result.succ(1, "新增成功", "");
        } else {
            return Result.fail("添加折点失败");
        }
    }

    @Override
    public Result updateBreakPoint(StaBreakPoint staBreakPoint) {
        int i = staBreakPointMapper.updateById(staBreakPoint);
        if (i > 0) {
            return Result.succ(1, "修改成功", "");
        } else {
            return Result.fail("修改折点失败");
        }
    }

    @Override
    public Result batchDeleteBreakPoint(StaBreakPointDto vo) {
        List<StaBreakPoint> bacBreakPointList = vo.getStaBreakPointList();
        //取出bacGermDictList中的id
        List<String> ids = bacBreakPointList.stream().map(StaBreakPoint::getId).collect(Collectors.toList());

        int i = staBreakPointMapper.deleteBatchIds(ids);
        if (i > 0) {
            return Result.succ(1, "删除成功", null);
        } else {
            return Result.fail(400, "删除失败", "");
        }
    }

    /*用户自定义折点 分类明细查询*/
    @Override
    public Result findCategoryByCode(StaBreakPointMapperCategoryParam input) {
        List<StaBreakPointMapperCategoryDto> res = new ArrayList<>();
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "ANAEROBE".toUpperCase().equals(input.getCateGoryCode())) {
            StaBreakPointMapperCategoryDto breakPointMapperCategoryDto = new StaBreakPointMapperCategoryDto();
            breakPointMapperCategoryDto.setCode("ANA");
            breakPointMapperCategoryDto.setName("厌氧");
            breakPointMapperCategoryDto.setCateGoryCode(input.getCateGoryCode());
            res.add(breakPointMapperCategoryDto);
            StaBreakPointMapperCategoryDto breakPointMapperCategoryDto1 = new StaBreakPointMapperCategoryDto();
            breakPointMapperCategoryDto1.setCode("");
            breakPointMapperCategoryDto1.setName("非厌氧");
            breakPointMapperCategoryDto1.setCateGoryCode(input.getCateGoryCode());
            res.add(breakPointMapperCategoryDto1);
            return Result.succ(1, "成功", res);
        }
        Map<String, List<StaGermDict>> groupList = null;
        LambdaQueryWrapper<StaGermDict> bacGermDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
        bacGermDictLambdaQueryWrapper.eq(StaGermDict::getDelFlag, 0);
        List<StaGermDict> germDicts = staGermDictMapper.selectList(bacGermDictLambdaQueryWrapper);

        if (ToolsUtils.isEmpty(germDicts)) {
            return Result.succ(1, "成功", res);
        }


        //.collect(Collectors.groupingBy(BacTestResult::getGermNo));
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "serumGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            germDicts = germDicts.stream().filter(bg -> ToolsUtils.isNotEmpty(bg.getSerumGroup())).collect(Collectors.toList());
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "2".equals(input.getFilterCondition())) {/*已 维护*/
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getSerovarGroup).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> serumGroupList.contains(bg.getSerumGroup())).collect(Collectors.toList());
                } else {
                    germDicts = germDicts.stream().filter(bg -> Arrays.asList("!@#QWE").contains(bg.getSerumGroup())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "3".equals(input.getFilterCondition())) {/*未维护 */
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getSerovarGroup).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> !serumGroupList.contains(bg.getSerumGroup())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getKeyword()) && ToolsUtils.isNotEmpty(germDicts)) {
                germDicts = germDicts.stream().filter(bg -> Arrays.asList(input.getKeyword()).contains(bg.getSerumGroup())).collect(Collectors.toList());
            }
            if (ToolsUtils.isEmpty(germDicts)) {
                return Result.succ(1, "成功", res);
            }
            groupList = germDicts.stream().collect(Collectors.groupingBy(StaGermDict::getSerumGroup));
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "WHONETORGCODE".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            germDicts = germDicts.stream().filter(bg -> ToolsUtils.isNotEmpty(bg.getGermNo())).collect(Collectors.toList());
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "2".equals(input.getFilterCondition())) {/*已 维护*/
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getWhonetOrgCode).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> serumGroupList.contains(bg.getGermNo())).collect(Collectors.toList());
                } else {
                    germDicts = germDicts.stream().filter(bg -> Arrays.asList("!@#QWE").contains(bg.getGermNo())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "3".equals(input.getFilterCondition())) {/*未维护 */
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getWhonetOrgCode).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> !serumGroupList.contains(bg.getGermNo())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getKeyword()) && ToolsUtils.isNotEmpty(germDicts)) {
                germDicts = germDicts.stream().filter(bg -> Arrays.asList(input.getKeyword()).contains(bg.getGermNo())).collect(Collectors.toList());
            }
            if (ToolsUtils.isEmpty(germDicts)) {
                return Result.succ(1, "成功", res);
            }
            groupList = germDicts.stream().collect(Collectors.groupingBy(StaGermDict::getGermNo));
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "speciesGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            germDicts = germDicts.stream().filter(bg -> ToolsUtils.isNotEmpty(bg.getSpeciesGroup())).collect(Collectors.toList());
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "2".equals(input.getFilterCondition())) {/*已 维护*/
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getSpeciesGroup).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> serumGroupList.contains(bg.getSpeciesGroup())).collect(Collectors.toList());
                } else {
                    germDicts = germDicts.stream().filter(bg -> Arrays.asList("!@#QWE").contains(bg.getSpeciesGroup())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "3".equals(input.getFilterCondition())) {/*未维护 */
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getSpeciesGroup).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> !serumGroupList.contains(bg.getSpeciesGroup())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getKeyword()) && ToolsUtils.isNotEmpty(germDicts)) {
                germDicts = germDicts.stream().filter(bg -> Arrays.asList(input.getKeyword()).contains(bg.getSpeciesGroup())).collect(Collectors.toList());
            }
            if (ToolsUtils.isEmpty(germDicts)) {
                return Result.succ(1, "成功", res);
            }
            groupList = germDicts.stream().collect(Collectors.groupingBy(StaGermDict::getSpeciesGroup));
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "genusCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            germDicts.stream().filter(bg -> ToolsUtils.isNotEmpty(bg.getGenusCode())).collect(Collectors.toList());
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "2".equals(input.getFilterCondition())) {/*已 维护*/
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getGenusCode).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> serumGroupList.contains(bg.getGenusCode())).collect(Collectors.toList());
                } else {
                    germDicts = germDicts.stream().filter(bg -> Arrays.asList("!@#QWE").contains(bg.getGenusCode())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "3".equals(input.getFilterCondition())) {/*未维护 */
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getGenusCode).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> !serumGroupList.contains(bg.getGenusCode())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getKeyword()) && ToolsUtils.isNotEmpty(germDicts)) {
                germDicts = germDicts.stream().filter(bg -> Arrays.asList(input.getKeyword()).contains(bg.getGenusCode())).collect(Collectors.toList());
            }
            if (ToolsUtils.isEmpty(germDicts)) {
                return Result.succ(1, "成功", res);
            }
            groupList = germDicts.stream().collect(Collectors.groupingBy(StaGermDict::getGenusCode));
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "genusGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            germDicts = germDicts.stream().filter(bg -> ToolsUtils.isNotEmpty(bg.getGenusGroup())).collect(Collectors.toList());
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "2".equals(input.getFilterCondition())) {/*已 维护*/
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getGenusGroup).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> serumGroupList.contains(bg.getGenusGroup())).collect(Collectors.toList());
                } else {
                    germDicts = germDicts.stream().filter(bg -> Arrays.asList("!@#QWE").contains(bg.getGenusGroup())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "3".equals(input.getFilterCondition())) {/*未维护 */
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getGenusGroup).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> !serumGroupList.contains(bg.getGenusGroup())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getKeyword()) && ToolsUtils.isNotEmpty(germDicts)) {
                germDicts = germDicts.stream().filter(bg -> Arrays.asList(input.getKeyword()).contains(bg.getGenusGroup())).collect(Collectors.toList());
            }
            if (ToolsUtils.isEmpty(germDicts)) {
                return Result.succ(1, "成功", res);
            }
            groupList = germDicts.stream().collect(Collectors.groupingBy(StaGermDict::getGenusGroup));
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "familyCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            germDicts = germDicts.stream().filter(bg -> ToolsUtils.isNotEmpty(bg.getFamilyCode())).collect(Collectors.toList());
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "2".equals(input.getFilterCondition())) {/*已 维护*/
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getFamilyCode).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> serumGroupList.contains(bg.getFamilyCode())).collect(Collectors.toList());
                } else {
                    germDicts = germDicts.stream().filter(bg -> Arrays.asList("!@#QWE").contains(bg.getFamilyCode())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "3".equals(input.getFilterCondition())) {/*未维护 */
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getFamilyCode).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> !serumGroupList.contains(bg.getFamilyCode())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getKeyword()) && ToolsUtils.isNotEmpty(germDicts)) {
                germDicts = germDicts.stream().filter(bg -> Arrays.asList(input.getKeyword()).contains(bg.getFamilyCode())).collect(Collectors.toList());
            }
            groupList = germDicts.stream().collect(Collectors.groupingBy(StaGermDict::getFamilyCode));
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "SubkingdomCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            germDicts = germDicts.stream().filter(bg -> ToolsUtils.isNotEmpty(bg.getSubKingdomCode())).collect(Collectors.toList());
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "2".equals(input.getFilterCondition())) {/*已 维护*/
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getSubkingdomCode).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> serumGroupList.contains(bg.getSubKingdomCode())).collect(Collectors.toList());
                } else {
                    germDicts = germDicts.stream().filter(bg -> Arrays.asList("!@#QWE").contains(bg.getSubKingdomCode())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getFilterCondition()) && "3".equals(input.getFilterCondition())) {/*未维护 */
                LambdaQueryWrapper<StaBreakPoint> bacBreakPointLambdaQueryWrapper = new LambdaQueryWrapper<>();
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
                bacBreakPointLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
                List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(bacBreakPointLambdaQueryWrapper);
                List<String> serumGroupList = bacBreakPoints.stream().map(StaBreakPoint::getSubkingdomCode).collect(Collectors.toList());
                if (ToolsUtils.isNotEmpty(serumGroupList)) {
                    germDicts = germDicts.stream().filter(bg -> !serumGroupList.contains(bg.getSubKingdomCode())).collect(Collectors.toList());
                }
            }
            if (ToolsUtils.isNotEmpty(input.getKeyword()) && ToolsUtils.isNotEmpty(germDicts)) {
                germDicts = germDicts.stream().filter(bg -> Arrays.asList(input.getKeyword()).contains(bg.getSubKingdomCode())).collect(Collectors.toList());
            }
            groupList = germDicts.stream().collect(Collectors.groupingBy(StaGermDict::getSubKingdomCode));
        }
        //germDicts.stream().collect(Collectors.groupingBy())
        if (CollectionUtils.isEmpty(groupList)) {
            return Result.succ(1, "查询", new ArrayList<>());
        }
        /*血清型*/
        List<Map<String, Object>> serumGroupList = (List<Map<String, Object>>) sysBasDictDetailService.getSysBasDictList("serumGroup").getData();
        /*种分组*/
        List<Map<String, Object>> speciesGroupList = (List<Map<String, Object>>) sysBasDictDetailService.getSysBasDictList("speciesGroup").getData();
        /*属编码*/
        List<Map<String, Object>> genusCodeList = (List<Map<String, Object>>) sysBasDictDetailService.getSysBasDictList("genusCode").getData();
        /*属分组*/
        List<Map<String, Object>> genusGroupList = (List<Map<String, Object>>) sysBasDictDetailService.getSysBasDictList("genusGroup").getData();
        /*科编码*/
        List<Map<String, Object>> familyCodeList = (List<Map<String, Object>>) sysBasDictDetailService.getSysBasDictList("familyCode").getData();
        /*亚界*/
        List<Map<String, Object>> SubkingdomCodeList = (List<Map<String, Object>>) sysBasDictDetailService.getSysBasDictList("SubkingdomCode").getData();

        /*循环赋值*/
        for (Map.Entry<String, List<StaGermDict>> entry : groupList.entrySet()) {
            StaBreakPointMapperCategoryDto breakPointMapperCategoryDto = new StaBreakPointMapperCategoryDto();
            breakPointMapperCategoryDto.setCateGoryCode(input.getCateGoryCode());
            breakPointMapperCategoryDto.setCode(entry.getKey());
            String Name = "";
            switch (input.getCateGoryCode()) {
                case "serumGroup":
                    serumGroupList.stream().filter(a -> a.get("code").equals(entry.getKey())).findFirst().ifPresent(stringObjectMap -> breakPointMapperCategoryDto.setName((String) stringObjectMap.get("name")));
                    break;
                case "speciesGroup":
                    speciesGroupList.stream().filter(a -> a.get("code").equals(entry.getKey())).findFirst().ifPresent(stringObjectMap -> breakPointMapperCategoryDto.setName((String) stringObjectMap.get("name")));
                    break;
                case "genusCode":
                    genusCodeList.stream().filter(a -> a.get("code").equals(entry.getKey())).findFirst().ifPresent(stringObjectMap -> breakPointMapperCategoryDto.setName((String) stringObjectMap.get("name")));
                    break;
                case "genusGroup":
                    genusGroupList.stream().filter(a -> a.get("code").equals(entry.getKey())).findFirst().ifPresent(stringObjectMap -> breakPointMapperCategoryDto.setName((String) stringObjectMap.get("name")));
                    break;
                case "familyCode":
                    familyCodeList.stream().filter(a -> a.get("code").equals(entry.getKey())).findFirst().ifPresent(stringObjectMap -> breakPointMapperCategoryDto.setName((String) stringObjectMap.get("name")));
                    break;
                case "SubkingdomCode":
                    SubkingdomCodeList.stream().filter(a -> a.get("code").equals(entry.getKey())).findFirst().ifPresent(stringObjectMap -> breakPointMapperCategoryDto.setName((String) stringObjectMap.get("name")));
                    break;
                case "WHONETORGCODE":
                    List<StaGermDict> stringObjectMap = entry.getValue();
                    breakPointMapperCategoryDto.setName(ToolsUtils.isNotEmpty(stringObjectMap) ? stringObjectMap.get(0).getGermNa() : entry.getKey());
                    break;
            }
            res.add(breakPointMapperCategoryDto);
        }
        return Result.succ(1, "查询成功", res);
    }

    @Override
    public Result findGermDictListByCode(StaBreakPointMapperCategoryParam input) {
        if (ToolsUtils.isEmpty(input.getBreakPointMapperCategoryDto())) {
            return Result.succ(1, "查询成功", new ArrayList<>());
        }
        Map<String, List<StaGermDict>> groupList = null;
        LambdaQueryWrapper<StaGermDict> bacGermDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
        bacGermDictLambdaQueryWrapper.eq(StaGermDict::getDelFlag, 0);

        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "serumGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaGermDict::getSerumGroup, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "speciesGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaGermDict::getSpeciesGroup, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "genusCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaGermDict::getGenusCode, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "genusGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaGermDict::getGenusGroup, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "familyCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaGermDict::getFamilyCode, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "SubkingdomCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaGermDict::getSubKingdomCode, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "WHONETORGCODE".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaGermDict::getGermNo, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "ANAEROBE".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            if (ToolsUtils.isNotEmpty(input.getBreakPointMapperCategoryDto().getCode()) && "ANA".equals(input.getBreakPointMapperCategoryDto().getCode())) {
                bacGermDictLambdaQueryWrapper.eq(StaGermDict::getIsAnaerobe, 1);
            }
        }
        if (ToolsUtils.isNotEmpty(input.getKeyword())) {
            bacGermDictLambdaQueryWrapper.and(p ->
                    p.like(StaGermDict::getGermNa, input.getKeyword())
                            .or()
                            .like(StaGermDict::getGermNo, input.getKeyword())
                            .or().
                            like(StaGermDict::getStandardNa, input.getKeyword())
                            .or()
                            .like(StaGermDict::getInputCode, input.getKeyword()));
        }

        List<StaGermDict> germDicts = staGermDictMapper.selectList(bacGermDictLambdaQueryWrapper);
        return Result.succ(1, "成功", germDicts);
    }

    @Override
    public Result findBreakPointListByCode(StaBreakPointMapperCategoryParam input) {
        if (ToolsUtils.isEmpty(input.getBreakPointMapperCategoryDto())) {
            return Result.succ(1, "查询成功", new ArrayList<>());
        }
        Map<String, List<StaBreakPoint>> groupList = null;
        MPJLambdaWrapper<StaBreakPoint> bacGermDictLambdaQueryWrapper = new MPJLambdaWrapper<>();
        bacGermDictLambdaQueryWrapper.selectAll(StaBreakPoint.class);
        bacGermDictLambdaQueryWrapper.selectAs(StaAntibioticsDict::getAntName, StaBreakPoint::getAntName);
        bacGermDictLambdaQueryWrapper.leftJoin(StaAntibioticsDict.class, StaAntibioticsDict::getAntCode, StaBreakPoint::getWhonetAbxCode);
        bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getDelFlag, 0);
        bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getGuidelines, "AUser-defined");
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "serumGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getSerovarGroup, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "speciesGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getSpeciesGroup, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "genusCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getGenusCode, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "genusGroup".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getGenusGroup, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "familyCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getFamilyCode, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "SubkingdomCode".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getSubkingdomCode, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "WHONETORGCODE".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getWhonetOrgCode, input.getBreakPointMapperCategoryDto().getCode());
        }
        if (ToolsUtils.isNotEmpty(input.getCateGoryCode()) && "ANAEROBE".toUpperCase().equals(input.getCateGoryCode().toUpperCase())) {
            if (ToolsUtils.isNotEmpty(input.getBreakPointMapperCategoryDto().getCode()) && "ANA".equals(input.getBreakPointMapperCategoryDto().getCode())) {
                bacGermDictLambdaQueryWrapper.eq(StaBreakPoint::getAnaerobe, "ANA");
            }
        }
        if (ToolsUtils.isNotEmpty(input.getKeyword())) {
            bacGermDictLambdaQueryWrapper.and(p ->
                    p.like(StaBreakPoint::getWhonetOrgCode, input.getKeyword())
                            .or()
                            .like(StaBreakPoint::getSerovarGroup, input.getKeyword())
                            .or().
                            like(StaBreakPoint::getSpeciesGroup, input.getKeyword())
                            .or()
                            .like(StaBreakPoint::getGenusCode, input.getKeyword())
                            .or()
                            .like(StaBreakPoint::getGenusGroup, input.getKeyword())
                            .or()
                            .like(StaBreakPoint::getFamilyCode, input.getKeyword())
                            .or()
                            .like(StaBreakPoint::getSubkingdomCode, input.getKeyword())
                            .or()
                            .like(StaBreakPoint::getAnaerobe, input.getKeyword()));
        }

        List<StaBreakPoint> germDicts = staBreakPointMapper.selectList(bacGermDictLambdaQueryWrapper);
        return Result.succ(1, "成功", germDicts);
    }

    @Override
    public Result findBreakPoints(Params params) {
        LambdaQueryWrapper<StaBreakPoint> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StaBreakPoint::getDelFlag, 0);
        if (!StringUtils.isEmpty(params.getSearchValue())) {
            queryWrapper.and(wrapper -> wrapper.like(StaBreakPoint::getOrganismCode, params.getSearchValue()));
        }

        List<StaBreakPoint> bacBreakPoints = staBreakPointMapper.selectList(queryWrapper);
        return Result.succ(1, "查询成功", bacBreakPoints);
    }
}
